namespace Radar.Test
{
    using System;
    using Moq;
    using NUnit.Framework;

    [TestFixture]
    public class ConstantFactoryBuilderTest
    {
        private class A { }

        private IFactoryBuilder builder;
        private IocConfiguration configuration;
        private Mock<IContainer> container;

        [SetUp]
        public void SetUp()
        {
            Func<object> f = () => new A();

            container = new Mock<IContainer>();
            configuration = new IocConfiguration(container.Object);

            builder = new ConstantFactoryBuilder(configuration, f);
        }

        [Test]
        public void WillMakeType()
        {
            var f = builder.GetFactoryMethod();

            var result = f(new ResolveContext());

            Assert.That(result, Is.InstanceOf<A>());
        }

        [Test, ExpectedException(typeof(ArgumentNullException))]
        public void WillThrowOnNullBuilderFunction()
        {
            new ConstantFactoryBuilder(configuration, null);
        }

        [Test, ExpectedException(typeof(ArgumentNullException))]
        public void WillThrowOnNullConfiguration()
        {
            new ConstantFactoryBuilder(null, () => new object());
        }
    }
}